"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
// 使用 Reflect Metadata 库来存储和读取元数据
require("reflect-metadata");
// 权限装饰器，用于添加元数据到方法上
function Permission(permission) {
    return function (target, propertyKey, descriptor) {
        Reflect.defineMetadata("permission", permission, target, propertyKey);
    };
}
// 用于在方法执行前检查权限的函数
function checkPermission(target, propertyKey) {
    // 从方法上读取权限元数据
    const requiredPermission = Reflect.getMetadata("permission", target, propertyKey);
    // 模拟权限检查逻辑
    if (requiredPermission !== "admin") {
        throw new Error("权限不足");
    }
}
class User {
    deleteAccount() {
        console.log("账户已删除");
    }
    execute(methodName) {
        // 在方法执行前检查权限
        checkPermission(this, methodName);
        // 执行方法
        this[methodName]();
    }
}
__decorate([
    Permission("admin") // 使用装饰器指定该方法需要 admin 权限
    ,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], User.prototype, "deleteAccount", null);
const user = new User();
try {
    user.execute("deleteAccount"); // 尝试执行需要权限的操作
}
catch (error) {
    console.error(error.message);
}
